<?php
declare (strict_types = 1);

namespace app\api\model\yuql;

use think\Model;

/**
 * @mixin \think\Model
 */
class Bargain extends Model
{
    protected $table = '2008a_store_bargain';
    /**
     * yuql
     * 查询砍价的这条商品
     * @param $data
     * @return Seckill|array|mixed|Model|null
     */
    public static function goodsOne($data){
        $result = Seckill::where($data)->find();
        return $result;
    }

    /**
     * yuql
     * 查询砍价后的商品信息
     * @param $data
     * @return Seckill|array|mixed|Model|null
     */
    public static function bargainGoodsOne($data){
        $result = Bargain::where($data)->find();
        return $result;
    }

    /**
     * yuql
     * 查询一个用户
     * @param $data
     * @return Seckill|array|mixed|Model|null
     */
    public static function userOne($data){
        $result = Login::where($data)->find();
        return $result;
    }

    /**
     * yuql
     * 第一次砍价时存入砍价库
     * @param $data
     * @return Bargain|Model
     */
    public static function bargainSet($data){
        $result = Bargain::create($data);
        return $result;
    }

    public static function bargainRecord($data){
        $result = BargainRecord::create($data);
        return $result;
    }

    /**
     * yuql
     * 根据砍价次数修改价格和砍价次数
     * @param $product_id
     * @param $bargain_num
     * @param $price
     */
    public static function bargainUpdate($product_id,$bargain_num,$price){
        $result = Bargain::where($product_id)->find();
        $result->bargain_num = $bargain_num;
        $result->price = $price;
        $result->save();
        return $result;
    }

}
